package com.app.community.mapper;

import com.app.community.dto.QuestionDTO;
import com.app.community.model.entity.Question;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 *  index对应的mapper
 * 2020/10/10 20:12
 **/
@Mapper
public interface IndexMapper {

    @Results({
            @Result(column = "question_id", property = "questionId"),
            @Result(column = "cover_pic",property = "questionCoverPic"),
            @Result(column = "nick_name",property = "nickName")
    })
    @Select({"select question_id,title,article,creator,date,question.cover_pic,summary,nick_name,avatar from question,user where creator=user_id order by date desc "})
    List<QuestionDTO> selectQuestionDTO();

    /**
     *  根据用户的搜索查询问题
     */
    @Results({
            @Result(column = "question_id", property = "questionId"),
            @Result(column = "cover_pic",property = "questionCoverPic"),
            @Result(column = "nick_name",property = "nickName")
    })
    @Select({"select question_id,title,article,creator,date,question.cover_pic,summary,nick_name,avatar from question,user where title regexp #{tags} and creator=user_id order by date desc"})
    List<QuestionDTO> searchQuestionDTO(@Param("tags")String tags);

    /**
     * 统计问题数量
     */
    @Select({"select count(question_id) from question;"})
    Integer selectQuestionCount();
}
